package com.taobao.shopcart.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

// Direct交换机
@Configuration
public class DirectConfiguration {

    @Bean
    // 定义一个DirectExchange类型的Bean，名称为taobao.direct
    public DirectExchange directExchange(){
        return new DirectExchange("taobao.direct");
    }
    @Bean
    public Queue directOrder(){
        return new Queue("direct.order");
    }
    @Bean
    public Queue directMsg(){
        return new Queue("direct.msg");
    }

    @Bean
    // 将directOrder绑定到directExchange，并指定routingKey为"order"
    public Binding directOrderBinding(Queue directOrder, DirectExchange directExchange){
        return BindingBuilder.bind(directOrder).to(directExchange).with("order");
    }
    @Bean
    // 将directOrder绑定到directExchange，并指定routingKey为"test"
    public Binding directOrderBindingTest(Queue directOrder, DirectExchange directExchange){
        return BindingBuilder.bind(directOrder).to(directExchange).with("test");
    }

    @Bean
    public Binding directMsgBinding(Queue directMsg, DirectExchange directExchange){
        return BindingBuilder.bind(directMsg).to(directExchange).with("msg");
    }
    @Bean
    public Binding directMsgBindingTest(Queue directMsg, DirectExchange directExchange){
        return BindingBuilder.bind(directMsg).to(directExchange).with("test");
    }


}
